package NC82_滑动窗口的最大值;

import java.util.*;
public class Solution {
    public ArrayList<Integer> maxInWindows(int [] num, int size) {
        ArrayList<Integer> res = new ArrayList<>();
        if (num == null || num.length < size){
            return res;
        }
        PriorityQueue<Integer> maxHeap = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        });
        int count = 0;
        for (;count < size; count++){
            maxHeap.offer(num[count]);
        }
        res.add(maxHeap.peek());
        while (count < num.length){
            maxHeap.remove(num[count - size]);
            maxHeap.offer(num[count]);
            res.add(maxHeap.peek());
            count++;
        }
        return res;
    }
}